﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Salomon/MP/Base.Master" AutoEventWireup="true" CodeBehind="ProEdit.aspx.cs" Inherits="WebsiteAdmin.Salomon.ProInfo.ProEdit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Head_Title" runat="server">产品编辑 - 产品</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Head_Meta" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Head_Css" runat="server">

<style type="text/css">
    div.hide{ display:none;}

		#Dialog {
			position: absolute; 
			z-index: 1000; 
			display: none;
			width: 600px;
			background: #FFFFFF;
			border: 3px #999999 solid; 
		}
		#Dialog h6 {
			width: 580px;
			height: 20px;
			line-height: 20px;
			margin: 0;
			padding: 5px 10px; 
			background: #EFEFEF;
			text-align: right; 
			
		}
		#Dialog div.box {
			width: 600px;
			max-height:500px;
			overflow-y:scroll;
		}
		
		#Dialog div#DialogHtml
		{
		    width: 560px;
			padding: 10px; 
			color: #999;
		}
		
		#DialogHtml a {
			float: left;
			height: 20px; 
			line-height: 20px; 
			margin: 5px 15px 5px 0;
			white-space: nowrap;
		}
		
		#DialogHtml h4{ clear:both; background-color:#efefef; font-size:13px; margin-top:5px; display:block; height: 20px; 
			line-height: 20px; padding:5px;}
		
		#DialogHtml b{ float:left; clear:left; height: 20px; 
		    background-color:#efefef;
			line-height: 20px; 
			margin: 3px 15px 3px 0;
			padding:2px;
			white-space: nowrap;}
		
		
        
        #DialogHtml h4 a,#DialogHtml b a{ margin: 0;}	
		
	</style>

</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="Head_Script" runat="server">
    <script type="text/javascript" src="/Script/Mootools.Smoothbox.js"></script>
	<script type="text/javascript" src="/CKEditor/CKEditor.js"></script>
	<script type="text/javascript" src="/CKFinder/CKFinder.js"></script>
<script type="text/javascript" language="javascript">
    var MenuViewID = 2;
    Array.implement({
        getFirstRadio: function() {
            if (this.length == 0) {
                return null;
            }
            return this[0];
        }
    });
    window.addEvent('domready', function() {
        if (typeof (CKEDITOR) == 'undefined' || typeof (CKFinder) == 'undefined') {
            alert('加载CKEditor或CKFinder失败');
        } else {
            CKFinder.setupCKEditor(null, '/CKFinder/');
            CKEDITOR.replace('txbProContent');
        }

        $('submitbtn').addEvent('click', function() {
            Submit();
        });
        
        $('ShowLink').addEvent('click', function() {
            BrowseServer('Images:/Product/', 'txbImgURL', 'ShowView');

        });
        
    });
    
    function SetFileField(fileUrl, data) {
        $(data["selectActionData"]).value = fileUrl;
        $(this).setProperty('src', fileUrl);
    }
    function BrowseServer(startupPath, functionData, element) {
        var finder = new CKFinder();
        finder.startupPath = startupPath;
        finder.selectActionData = functionData;
        finder.selectActionFunction = SetFileField.bind(element);
        finder.popup();
    }

    function ShowCat() {
        LightBox.show();
        $('DialogHtml').set('html', $('CatList').get('html'));
        ShowDialog();
    }

    function CloseDialog() {
        var obj = $('Dialog');
        if (obj.getStyle('display') != 'none') {
            $('DialogHtml').empty();
            obj.hide();
            LightBox.remove();
        }
    }

    function ShowDialog() {
        var scrollsize = $(window).getScroll();
        var allwindowSize = window.getSize();
        var dialogSize = $('Dialog').measure(function() {
            return this.getSize();
        });
        $('Dialog').setStyles({ 'left': scrollsize.x + (allwindowSize.x - dialogSize.x) / 2, 'top': scrollsize.y + (allwindowSize.y - dialogSize.y) / 2 }).show();
    }

    function CatSelect(e, t) {
        if ($('txbCatID').get('value') != e) {
            $('txbSerName').set('value', '');
            $('txbSerID').set('value', '');
        }
        $('txbCatName').set('value', t);
        $('txbCatID').set('value', e);
        CloseDialog();
        LightBox.remove();
    }

    function SerSelect() {
        var txbCatID = $('txbCatID').get('value');
        if (!isNaN(txbCatID)) {
            var myRequest = new Request.JSON({
                url: 'Handler/SerList.ashx',
                data: {
                    PKID: txbCatID
                },
                method: "post",
                noCache: true,
                onFailure: function(xhr) {
                    alert(xhr.statusText);
                    LightBox.remove();
                },
                onSuccess: function(data, text) {
                    if (data.length > 0) {
                        data.each(function(item, index) {
                            var obj = new Element('a');
                            obj.set('href', 'javascript:SeriesSelected("' + item.PKID + '","' + item.SerName + '");');
                            obj.set('text', item.SerName);
                            $('DialogHtml').adopt(obj);
                            ShowDialog();
                        });
                    } else {
                        $('DialogHtml').set('html', '暂无数据');
                        ShowDialog();
                    }
                }
            }).send();
        }
        else {
            alert('请先选择分类');
        }
    }

    function SeriesSelected(e, t) {
        $('txbSerName').set('value', t);
        $('txbSerID').set('value', e);
        CloseDialog();
        LightBox.remove();
    }
    
    function getContents(e) {
			var oEditor = CKEDITOR.instances[e];
			if (oEditor != null) {
				return(oEditor.getData());
			} else {
				return "";
			}
	}
    
    function Submit() {
        var txbCatID = $('txbCatID').get('value').trim().toInt();
        if (isNaN(txbCatID)) {
            alert('请选择产品分类');
            return false;
        }
        var txbSerID = $('txbSerID').get('value').trim().toInt();
        if (isNaN(txbSerID)) {
            alert('请选择产品系列');
            return false;
        }
        
        var txbProName = $('txbProName').get('value').trim();
        if (txbProName.length == 0) {
            alert('产品标题错误');
            return false;
        }
        var txbKeywords = $('txbKeywords').get('value').trim();
        var txbDescription = $('txbDescription').get('value').trim();
        
        
        var txbProCode = $('txbProCode').get('value').trim();
        if (txbProCode.length == 0) {
            alert('请输入产品显示链接');
            return false;
        }
        var txbImgURL  = $('txbImgURL').get('value').trim();
        
        var txbProContent = getContents('txbProContent').trim();
        if (txbProContent.length == 0) {
            alert('请输入产品介绍');
            return false;
        }
        
        var txbSortOrder = $('txbSortOrder').get('value').trim().toInt();
        if (isNaN(txbSortOrder)) {
            alert('必须是整数');
            return false;
        }
        Update(
            txbCatID,
            txbSerID,
            txbProName,
            txbKeywords,
            txbDescription,
            txbProCode,
            txbImgURL,
            txbProContent,
            txbSortOrder);
    }
    
    function Update(txbCatID,
        txbSerID,
        txbProName,
        txbKeywords,
        txbDescription,
        txbProCode,
        txbImgURL,
        txbProContent,
        txbSortOrder) {

        new Request.JSON({
            method: 'post',
            url: 'Handler/ProUpdate.ashx',
            data: {
                PKID:<%=pkid %>,
                CatID: txbCatID,
                SerID: txbSerID,
                ProName : txbProName,
                Keywords : txbKeywords,
                Description: txbDescription,
                ProCode : txbProCode,
                ImgURL : txbImgURL,
                ProContent : txbProContent,
                SortBy: txbSortOrder
            },
            noCache: true,
            onSuccess: function(data, text) {
                if (data.Done == 'Success') { 
                    
                    if(confirm('修改成功，返回列表？'))
                    {
                        document.location.href = '/Salomon/ProInfo/ProList.aspx';
                    };
                    LightBox.remove();
                }
                else
                {
                    alert('修改失败');
                    LightBox.remove();
                }
            },
            onFailure: function(xhr) {
                alert(xhr.statusText);
                LightBox.remove();
            }
        }).send();
    }
    
</script>
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="Body_Top" runat="server">
</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="Body_Content" runat="server">
     <div class="infobox">
        <h3>
        <span>产品编辑</span>
			<a href="/Salomon/ProInfo/ProList.aspx" class="back action">返回产品列表</a>
        </h3>
        <div class="mt10">
        <form id="myForm" action="">
		    <table border="0" cellpadding="0" cellspacing="0" class="table_form">
		        <tr>
            		<td align="right" width="100"><span class="Need">所属分类：</span></td>
            		<td>
            			<input name="txbCatName" type="text" id="txbCatName" style="color:#666; background-color:#efefef; border:1px #ccc solid; <% if(catValid == 0){ Response.Write("text-decoration:line-through;");}%>" readonly="readonly" value="<%=catName %>" /> <a href="javascript:void(0);" onclick="javascript:ShowCat();" >选择分类</a>
            			<input type="hidden" value="<%=catID %>" id="txbCatID" name="txbCatID" />
            		</td>
				</tr>
				<tr>
            		<td align="right" width="100"><span class="Need">所属系列：</span></td>
            		<td>
            			<input name="txbSerName" type="text" id="txbSerName" style="color:#666; background-color:#efefef; border:1px #ccc solid; <% if(serValid == 0 || catValid == 0){ Response.Write("text-decoration:line-through;");}%>" readonly="readonly" value="<%=serName %>" /> <a href="javascript:void(0);" onclick="javascript:SerSelect();">选择系列</a>
            			<input type="hidden" value="<%=serID %>" id="txbSerID" name="txbSerID" />
            		</td>
				</tr>
		        
		        <tr>
            		<td align="right" width="100"><span class="Need">产品名称：</span></td>
            		<td>
            			<input name="txbProName" type="text" id="txbProName"  maxlength="40" size="40" style="width:300px;" value="<%=proName %>" />
            		</td>
				</tr>
				<tr>
            		<td align="right" width="100"><span class="Need">显示链接：</span></td>
            		<td>
            			<input name="txbProCode" type="text" id="txbProCode" maxlength="20" size="20" value="<%=proCode %>" /><i>.html
            			限20个字符，例 service、fuwu</i>
            		</td>
				</tr>
				<tr>
            		<td align="right" width="100">关键词：</td>
            		<td>
            			<input name="txbKeywords" type="text" id="txbKeywords" maxlength="50" size="50" value="<%=keywords %>" />
            		</td>
				</tr>
				<tr>
            		<td align="right" width="100"><span class="Need">简介：</span></td>
            		<td>
            			<textarea name="txbDescription" rows="3" cols="20" id="txbDescription"><%=description %></textarea>
            		</td>
				</tr>
				<tr>
                    <td align="right" width="100">
                        图片：</td>
                    <td>
                           <input type="text" id="txbImgURL" name="txbImgURL" style="width:450px; color:#666; background-color:#efefef; border:1px #ccc solid;" readonly="readonly" value="<%=imgURL %>"  /> <font color="red">*&nbsp;</font>
                           <a id="ShowLink" style="cursor:pointer;cursor:hand;border:solid 1px;padding:0 10px 0 10px;">浏览</a>
                    </td>
                </tr>
                <tr>
                    <td align="right" width="100">&nbsp;</td>
                    <td>
                        <div style=" width:126px; height:147px; overflow:hidden; border:1px #999 solid; background-color:#f8f8f8; clear:both;">
                           <img id="ShowView" alt="" src="<%=imgURL %>" />
                        </div>
                        <i>图片尺寸 126 x 147。</i><br />
                        <i>如果图片不能完全填充，请重新选择图片。</i>
                    </td>
                </tr>
				<tr>
            		<td align="right" width="100"><span class="Need">显示排序：</span></td>
            		<td>
            			<input name="txbSortOrder" type="text" id="txbSortOrder" maxlength="2" size="5" value="<%=sortBy %>" />
            			<i>请输入数字</i>
            		</td>
				</tr>
							
				<tr>
					<td align="right"><span class="Need">产品介绍：</span></td>
					<td>
						<textarea name="txbProContent" rows="14" cols="20" id="txbProContent"><%=proContent%></textarea>
						<i>限2000汉字(4000字符)</i>
					</td>
				</tr>
		    </table>
		    <table border="0" cellpadding="0" cellspacing="0" class="table_form">
				<tr>
					<td width="100" height="40">&nbsp;</td>
					<td>
						<input id="submitbtn" type="button" value="提交" class="btn" />
						<input type="reset" value="重置" class="btn" />
					</td>
				</tr>
			</table>
		</form>
        </div>
    </div>
    <div id="Dialog">
		<h6>
			<a href="javascript:CloseDialog();">CLOSE</a>
		</h6>
		<div class="box">
		    <div id="DialogHtml"></div>
		</div>
	</div>
	<div class="hide" id="CatList">
	    <asp:Repeater ID="RP_Category" EnableViewState="False" runat="server" OnItemDataBound="RP_Category_ItemDataBound">
			<ItemTemplate>
			    <asp:Label ID="CatSelect" runat="server" />
			</ItemTemplate>
		</asp:Repeater>
	</div>
	
	
</asp:Content>
<asp:Content ID="Content7" ContentPlaceHolderID="Body_Foot" runat="server"  >
</asp:Content>